<!DOCTYPE html>
<html lang="zh-CN" ng-app="formModule">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
		<title>注册页面</title>

		<!-- Bootstrap -->
		<link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

		<!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
		<!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
		<script src="js/plugins/angularjs/angular.min.1.5.8.js"></script>
		<script src="js/plugins/angularjs/angular-messages.js"></script>
	</head>
	<body ng-controller="registController">
		<!-- 导航条 -->
		<ng-include src="'nav.html'"></ng-include>
		<!-- 注册表 -->
		<div class="container">
			<form class="form-horizontal" name="myform" novalidate>
				<div class="form-group">
					<div class="col-md-offset-5 "><strong>&nbsp&nbsp&nbsp&nbsp会员注册</strong></div>
				</div>
				<div class="form-group">
					<label for="inputName3" class="col-md-2 control-label col-md-offset-3">用户名</label>
					<div class="col-md-3">
						<input type="text" class="form-control" id="inputName3" ng-blur="checkUsername()" placeholder="用户名" ng-model="user.username" name="inputName" ng-maxlength="20"
						 required="required" >
						 <span>{{errMessage}}</span>
						 <span>{{infoMessage}}</span>
					</div>
					<div class="col-md-2">
						<span ng-show="myform.inputName.$error.maxlength">长度不能超过20位</span>
					</div>
				</div>
				<div class="form-group">
					<label for="inputPassword3" class="col-md-2 control-label col-md-offset-3">密码</label>
					<div class="col-md-3">
						<input type="password" class="form-control" id="inputPassword3" ng-model="user.pwd" placeholder="密码" name="passWord" ng-maxlength="20"
						 ng-minlength="6" required="required">
					</div>
					<div class="col-md-2" ng-messages="myform.passWord.$error">
						<div ng-message="maxlength">长度不能超过20位</div>
						<div ng-message="minlength">长度不能少于6位</div>
					</div>
				</div>
				<div class="form-group">
					<label for="inputCheckPassword3" class="col-md-2 control-label col-md-offset-3">确定密码</label>
					<div class="col-md-3">
						<input type="password" class="form-control" id="inputCheckPassword3" placeholder="确定密码" name="passCheckWord" ng-maxlength="20"
						 ng-minlength="6" required="required" ng-model="passCheckWord">
					</div>
					<div class="col-md-2" ng-messages="myform.passCheckWord.$error">
						<div ng-message="maxlength">长度不能超过20位</div>
						<div ng-message="minlength">长度不能少于6位</div>
					</div>
				</div>
				<div class="form-group">
					<label for="inputEmail3" class="col-md-2 col-md-offset-3 control-label">Email</label>
					<div class="col-md-3">
						<input type="email" class="form-control" id="inputEmail3" placeholder="Email" name="email" ng-model="email">
					</div>
					<div class="col-md-2" ng-messages="myform.email.$error">
						<div ng-message="email">Email地址不合法！</div>
					</div>
				</div>
				<div class="form-group">
					<label for="inputName2" class="col-md-2 control-label col-md-offset-3">姓名</label>
					<div class="col-md-3">
						<input type="text" class="form-control" id="inputName2" placeholder="姓名" name="string" ng-model="string" ng-minlength="2">
					</div>
					<div class="col-md-2" ng-messages="myform.string.$error">
						<div ng-message="minlength">长度不能少于2位</div>
					</div>
				</div>
				<div class="form-group">
					<label for="inputGender" class="col-md-2 control-label col-md-offset-3">性别</label>
					<div class="col-md-3">
						<label class="radio-inline">
							<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> 男
						</label>
						<label class="radio-inline">
							<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2"> 女
						</label>
					</div>
				</div>
				<div class="form-group">
					<label for="inputDirsday" class="col-md-2 control-label col-md-offset-3">出生日期</label>
					<div class="col-md-3">
						<input type="datetime" class="form-control" id="inputDirsday" placeholder="年/月/日" name="datetime" ng-model="datetime" ng-pattern="/^(?:(?!0000)[0-9]{4}\/(?:(?:0[1-9]|1[0-2])\/(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])\/(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/">
					</div>
					<div class="col-md-2" ng-messages="myform.datetime.$error">
						<div ng-message="pattern">输入不合法</div>
					</div>
				</div>
				<div class="form-group">
					<label for="inputVerify" class="col-md-2 control-label col-md-offset-3">验证码</label>
					<div class="col-md-2">
						<input type="text" class="form-control" id="inputVerify" placeholder="验证码">
					</div>
					<div class="col-md-1">
						<input type="text" class="form-control" id="inputVerify1">
					</div>
				</div>
				<div class="form-group">
					<div class="row">
						<div class="col-md-offset-5 col-md-3">
							<button type="button" class="btn btn-primary btn-block" ng-click="registSubmit()">登录</button>
						</div>
					</div>
				</div>
			</form>
		</div>
		<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
		<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
		<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
		<script>
			var app=angular.module('formModule', ['ngMessages']);
			app.service("userService",function($http){
				this.regist=function(datas){
					return $http.post("regist.user",datas);
				}
				this.checkUserName=function(username){
					//return $http.post("checkname.user",datas);
					return $http.get("checkname.user?username="+username);
				}
			});
			app.controller("registController",function($scope,userService){
				$scope.registSubmit=function(){
					console.log($scope.user);
					userService.regist(JSON.stringify($scope.user)).then(function success(response){
						console.log(response);
						if(response.data.flag==true){
							location.href="./login.html";
						}else{
							alter(response.data.message);
						}
					});
				}
				$scope.checkUsername=function(){
					userService.checkUserName($scope.user.username).success(function(response){
						console.log(response);
						$scope.errMessage=response.message;
					});
				}
			});
		</script>
	</body>
</html>
